﻿///   <reference path="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.2.min.js" />


$(document).ready(
function () {
    $.getJSON('http://localhost:1234/TwitterChatService.svc/Channels/All', function (data) {
        for (i in data) {
            $('#channels').append('<li id="' + data[i].ID + '" value="' + data[i].ChannelName + '">' + data[i].ChannelName + '</li>');
        }

        $('#channelNameHeader').html('Channel: ' + data[0].ChannelName);
        $('#channels li:first').addClass('selected');


    });

    var currentChannel = $('.selected').html();
    var link = "http://localhost:1234/TwitterChatService.svc/Channels/" + currentChannel;
    $.getJSON(link, function (data) {
        for (i in data) {
            $('#chatWindowContent').append(data[i].MessageText + '<br />');
        }
    });

    $('#channels li').click(function () {
        $('#chatWindowContent').empty();
        $('#channels li').removeClass('selected');
        $(this).addClass('selected');

        var currentChannel = $('.selected').html();
        var link = "http://localhost:1234/TwitterChatService.svc/Channels/" + currentChannel;
        $.getJSON(link, function (data) {
            for (i in data) {
                $('#chatWindowContent').append(data[i].MessageText + '<br />');
            }
        });
    });
});
